/*
 * @(#)AjaxController.java
 *
 * Copyright 2011-10-31 北龙中网(北京)科技有限责任公司, Inc. All rights reserved.
 */
package cn.shangjia.shop.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.shangjia.common.util.image.FileUploadUtils;
import cn.shangjia.shop.controller.base.AbstractController;


/**
 * @description 
 * @author <a href="mailto:wangxin@knet.cn">wangxin</a>
 * @version 
 * @date 2011-11-11 上午10:34:16
 */
@Controller
public class AjaxController extends AbstractController{
	
	/**
	 * 
	 * 通过异步ajax实现页面传入图片key并返回图片url或者默认图片的方法.
	 *
	 * @param imgkey
	 * @return
	 * @author <a href="mailto:wangxin@knet.cn">wangxin</a>
	 */
	@ResponseBody
	@RequestMapping("/shop/ajax/getimage.html")
	public String getImage(String imgkey) {
		try {
			boolean isExist = FileUploadUtils.exist(imgkey);
			if (isExist) 
				return FileUploadUtils.getFile(imgkey);
		} catch (Exception e) {
			logger.errorPair(e, "获取图片返回异常,已经返回默认图片", imgkey);
		}
		return "/static/images/default.jpg";
	}

}
